<?php get_instance()->view('common/header');?>
<link href="<?php echo $this->staticUrl?>video/css/video-js.min.css" rel="stylesheet" type="text/css">
<script src="<?php echo $this->staticUrl?>video/js/video.min.js"></script>
<style>
.huifuimgbox{height:auto;}
.huifuimgbox .imgbox{width:30%;margin-bottom:0.5em;}
</style>
<body>
<div class="tabcard bor_bb">
    <a href="<?php echo getUrl('friendsCircle/buyers')?>" <?php if ($type == 1 ):?>class="actived" <?php endif;?> >买家秀</a>
    <a href="<?php echo getUrl('friendsCircle/seller')?>" <?php if ($type == 2 ):?>class="actived" <?php endif;?> >卖家秀</a>
</div>
<div class="list pb50">
    <?php if (!empty($list['list'])): foreach ($list['list'] as $k => $v):?>
        <div class="bor_tt p3p">
            <a  <?php if ($type == 1):?> href="<?php echo $v['consumer_id'] == $this->userId ? getUrl('friendsCircle/myFriendsCircle') : getUrl('friendsCircle/index?type=1&id='.$v['consumer_id'])?>"
                <?php else:?> href="<?php echo getUrl('friendsCircle/index?type=2&id='.$v['merchant_id'])?>" <?php endif;?>
            >
                <div class="hengleft">
                    <div class="minuserimg imgbox"><img src="<?php echo $v['portrait']['xs']?>" alt=""></div>
                    <div class="">
                        <h1><?php echo $v['nickname']?></h1>
                        <p class="f07 pjdatatime"><?php echo $v['addtime']?></p>
                    </div>
                </div>
            </a>
            <div class="huifu">
                <a href="<?php echo getUrl('friendsCircle/details?fid='.$v['id'].'&type='.$type)?>">
                    <p class="m5_0 f09"><?php echo $v['content']?></p>
                    <?php if (!empty($v['image'])):?>
                        <div class="huifuimgbox imgboxpull">
                            <?php foreach ($v['image'] as $kk => $vv):?>
                                <div class=" imgbox"><img src="<?php echo $vv['og']?>" alt=""></div>
                            <?php endforeach; ?>
                        </div>
                    <?php endif;?>
                    <?php if(!empty($v['video'])): ?>
                        <div class="imgbox">
                            <video
                                    class="video-js vjs-default-skin" controls preload="none" poster="<?php echo $v['coverUrl']?>" style="width:100%;height:100%;">
                                <source src="<?php echo $v['video']?>" type='video/mp4' />
                            </video>
                        </div>
                    <?php endif;?>
                    <div class="textEll f08 cor9 heng">
                        <div>
                            浏览<?php echo $v['browse_number']?>次
                            <span class="cor9 ml10 f10"><?php echo $v['address']?></span>
                        </div>
                        <div class="vCenter f12">
                            <a href="javascript:;" class="mr10 praise pr" data-id="<?php echo $v['id']?>">
                                <?php if ($v['praise'] == 1):?>
                                    <img src="<?php echo $this->staticUrl?>img/png/pic88.png" class="heightimg" alt="">
                                <?php else:?>
                                    <img src="<?php echo $this->staticUrl?>img/png/pic87.png" class="heightimg" alt="">
                                <?php endif;?>
                            </a>
                            <?php if($v['praise_count']):?>
                            <span class="f08 cor3 mr10"><?php echo $v['praise_count'];?></span>
                            <?php endif;?>
                            <a href="<?php echo getUrl('friendsCircle/details?type='.$type.'&fid='.$v['id'])?>"><img class="heightimg" src="<?php echo $this->staticUrl?>img/png/pic103.png" alt=""></a>
                        </div>
                    </div>
                </a>
            </div>
        </div>
    <?php endforeach; else:?>
        <div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">
            <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/default/2.png" alt="">
            <span class="f09 cor9 tc mb20">暂无数据</span>
        </div>
    <?php endif;?>
    <div class="weui-loadmore" style="display: none">
        <div class="load">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        <span class="noC" style="display: none">没有更多内容了~</span>
    </div>
</div>
<?php get_instance()->view('common/footer');?>
<?php if($type == 1):?>
<div class="posibtn">
    <a href="<?php echo getUrl('friendsCircle/add')?>"><img src="<?php echo $this->staticUrl?>img/png/pic133.png" alt=""></a>
</div>
<?php endif;?>
</body>
<script src="<?php echo $this->staticUrl?>js/jquery-weui.js"></script>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    $(function () {
        var type = "<?php echo $type?>";
        
        /**
         * 上拉加载
         */
        var page = "<?php echo $list['page']?>";
        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            $(".weui-loadmore").show();
            $(".load").show();
            $(".noC").hide();
            // $(document.body).destroyInfinite() // 销毁插件
            // $(document.body).infinite() // 重新初始化
            $.ajax('<?php echo getUrl('friendsCircle/getList');?>', {
                type:'post',
                data:{page:page,type:type},
                dataType:'json',
                error:function(){
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e){
                    loading = false;
                    if (!e.data.list.length){
                        $(document.body).destroyInfinite();
                        $(".load").hide();
                        $(".noC").show();
                        return;
                    }
                    page = e.data.page  ;
                    $(".weui-loadmore").hide();
                    var html,
                        detailsUrl = "<?php echo getUrl('friendsCircle/details?type=')?>"+type,
                        indexUrl = "<?php echo getUrl('friendsCircle/index')?>",
                        img = "<?php echo $this->staticUrl?>img/png/pic103.png";
                    $.each(e.data.list, function (key, obj) {
                        var image = '',praise, url;
                        if (obj.image.length){
                            image = '<div class="huifuimgbox imgboxpull">';
                            $.each(obj.image,function (k, v) {
                                image += ' <div class=" imgbox"><img src="'+v.og+'" alt=""></div>';
                            });
                            image += '</div>';
                        }

                        if (obj.praise == 1){
                            praise = '<img src="<?php echo $this->staticUrl?>img/png/pic88.png" class="heightimg" alt="">';
                        }else{
                            praise = '<img src="<?php echo $this->staticUrl?>img/png/pic87.png" class="heightimg" alt="">';
                        }
                        praise_count = '';
                        if(obj.praise_count){
                            praise_count = obj.praise_count;
                        }
                        if (type == 1){
                            indexUrl = indexUrl + '?type=1&id=' + obj.consumer_id;
                        }else{
                            indexUrl = indexUrl + '?type=2&id=' + obj.merchant_id;
                        }
                        html =
                            '<div class="bor_tt p3p">'+
                            '   <a href="'+indexUrl+'"><div class="hengleft">'+
                            '      <div class="minuserimg imgbox"><img src="'+obj.portrait.xs+'" alt=""></div>'+
                            '      <div class="">'+
                            '          <h1>'+obj.nickname+'</h1>'+
                            '          <p class="f07 pjdatatime">'+obj.addtime+'</p>'+
                            '      </div>'+
                            '   </div></a>'+
                            '   <div class="huifu"><a href="'+detailsUrl+'">'+
                            '       <p class="m5_0 f09">'+obj.content+'</p>'+image+
                            '       <div class="textEll f08 cor9 heng">'+
                            '           <div>浏览'+obj.browse_number+'次'+
                            '               <a href="" class="cor9 ml10">'+obj.address+'</a>'+
                            '           </div>'+
                            '           <div class="vCenter f12">'+
                            '               <a href="javascript:;" class="mr10 praise pr" data-id="'+obj.id+'">'+praise+
                            '               </a><span class="f08 cor3 mr10">'+praise_count+'</span>'+
                            '               <a href="'+detailsUrl+'&fid='+obj.id+'"><img class="heightimg" src="'+img+'" alt=""></a>'+
                            '           </div>'+
                            '       </div>'+
                            '   </a></div>'+
                            '</div>';
                        $(".list").append(html);
                    });
                }
            });
        });

        /**
         * 点赞
         */
        $(".list").delegate('.praise', 'click', function () {
            blockUI.show();
            var id = $(this).attr('data-id'),
                praise_image,
                _this = $(this)
            ;
            $.ajax('<?php echo getUrl('friendsCircle/praise');?>', {
                dataType:'json',
                type:'post',
                data:{fid:id,type:type},
                error:function(){
                    blockUI.hide();
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e,textStatus,jqXHR){
                    blockUI.hide();
                    show_message(e);
                    if (e.status == 1) {
                        if (e.data.status == 1){
                            // 未点赞
                            praise_image = '<?php echo $this->staticUrl?>img/png/pic87.png';
                        }else{
                            // 已点赞
                            praise_image = '<?php echo $this->staticUrl?>img/png/pic88.png';
                        }
                        _this.find('img').attr('src', praise_image);
                    }
                }
            });
        });
    })
</script>
</html>